var e = require("../../../../@babel/runtime/helpers/defineProperty"), t = require("../../../../mycomponent/yz_pay/yz_pay"), a = getApp();

Page({
    behaviors: [ t ],
    data: {
        language: "",
        value: "",
        every_value: "",
        transform_value: "",
        title: "",
        money: "",
        pay_type: "",
        converge_wechat_pay: !1,
        weixinShow: !1,
        buttons: []
    },
    onLoad: function(e) {
        this.initData(), this.getData(), this.getTitle();
    },
    onReady: function() {
        var e = wx.getStorageSync("langIndex");
        this.setData({
            language: e.en
        });
    },
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {},
    getData: function() {
        var e = this, t = a.getNetAddresss("plugin.love.Frontend.Modules.Love.Controllers.recharge.page");
        a._getNetWork({
            url: t,
            success: function(t) {
                var a = t.data;
                1 === a.result && e.setData({
                    value: a.data.member_usable,
                    every_value: a.data.recharge_rate_money,
                    transform_value: a.data.recharge_rate_love,
                    converge_wechat_pay: a.data.converge_wechat_pay
                });
            },
            fail: function(e) {
                console.log(e);
            }
        });
    },
    getTitle: function() {
        var t = this, n = this, o = a.getNetAddresss("plugin.love.Frontend.Controllers.page.index");
        a._getNetWork({
            url: o,
            success: function(a) {
                var o = a.data;
                if (1 === o.result) {
                    t.setData({
                        title: o.data.love_name,
                        buttons: o.data.buttons
                    }), wx.setNavigationBarTitle({
                        title: o.data.love_name ? o.data.love_name + "充值" : "充值"
                    });
                    for (var s = 0; s < n.data.buttons.length; s++) n.data.buttons[s] && n.setData(e({}, "buttons[" + s + "].btclass", n.btnclass(n.data.buttons[s].value)));
                    1 == o.data.weixin && t.setData({
                        weixinShow: !0
                    });
                } else wx.showToast({
                    title: o.msg,
                    icon: "none",
                    image: "",
                    duration: 1500,
                    mask: !1
                });
            },
            fail: function(e) {
                console.log(e);
            }
        });
    },
    initData: function() {
        this.value = "", this.every_value = "", this.transform_value = "", this.title = "", 
        this.money = "", this.pay_type = "";
    },
    rechargeHandel: function(e) {
        var t = this;
        if (this.setData({
            pay_type: e.currentTarget.dataset.val
        }), this.data.money) {
            var n = a.getNetAddresss("plugin.love.Frontend.Modules.Love.Controllers.recharge.index");
            n += "&pay_way=" + this.data.pay_type, n += "&recharge_money=" + this.data.money, 
            n += "&client_type=2", a._getNetWork({
                url: n,
                success: function(e) {
                    console.log(e), 1 === e.data.result ? t.rechargePay(t.data.pay_type, e, e.data.ordersn) : wx.showToast({
                        title: e.data.msg,
                        icon: "none",
                        image: "",
                        duration: 1500,
                        mask: !1
                    });
                },
                fail: function(e) {
                    console.log(e);
                }
            });
        } else wx.showToast({
            title: "充值数量不能为空",
            icon: "none",
            duration: 1500
        });
    },
    confirm: function(e) {
        var t = this, n = e.currentTarget.dataset.val;
        if (this.data.money <= 0) wx.showToast({
            icon: "none",
            title: "金额不可低于0",
            duration: 1500
        }); else {
            this.setData({
                money: parseFloat(this.data.money),
                pay_type: n
            });
            var o = a.getNetAddresss("plugin.love.Frontend.Modules.Love.Controllers.recharge.index");
            o += "&client_type=2", o += "&app_type=wechat", o += "&pay_way=" + this.data.pay_type, 
            o += "&recharge_money=" + this.data.money, a._getNetWork({
                url: o,
                success: function(e) {
                    var o = e.data;
                    if (1 == o.result) {
                        if (a._isTextEmpty(o.data.order_sn)) return wx.showToast({
                            icon: "none",
                            title: "参数错误",
                            duration: 1500
                        }), !1;
                        t.setData({
                            ordersn: o.data.order_sn
                        }), t.rechargePay(n, o, o.data.ordersn);
                    } else wx.showToast({
                        icon: "none",
                        title: o.msg,
                        duration: 1500
                    });
                },
                fail: function(e) {
                    console.log(e);
                }
            });
        }
    },
    onChange: function(e) {
        this.setData({
            money: e.detail
        });
    }
});